﻿using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

// Code scaffolded by EF Core assumes nullable reference types (NRTs) are not used or disabled.
// If you have enabled NRTs for your project, then un-comment the following line:
// #nullable disable

namespace car.Models
{
    public partial class carContext : DbContext
    {
        public carContext()
        {
        }

        public carContext(DbContextOptions<carContext> options)
            : base(options)
        {
        }

        public virtual DbSet<Admin> Admin { get; set; }
        public virtual DbSet<Order> Order { get; set; }
        public virtual DbSet<Trip> Trip { get; set; }
        public virtual DbSet<User> User { get; set; }
        public virtual DbSet<Vehicle> Vehicle { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. See http://go.microsoft.com/fwlink/?LinkId=723263 for guidance on storing connection strings.
                optionsBuilder.UseMySql("persist security info=True;data source=rm-bp10zo4yzj78ie97yfo.mysql.rds.aliyuncs.com;port=3306;initial catalog=db_car;user id=wqy;password=wqy15706036031;character set=utf8;allow zero datetime=true;convert zero datetime=true;pooling=true;maximumpoolsize=3000", x => x.ServerVersion("5.7.35-mysql"));
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Admin>(entity =>
            {
                entity.HasKey(e => e.Aid)
                    .HasName("PRIMARY");

                entity.ToTable("admin");

                //entity.HasIndex(e => e.Aid)
                //    .HasName("AID_index")
                //    .IsUnique();

                entity.Property(e => e.Aid)
                    .HasColumnName("AID")
                    .HasColumnType("char(18)")
                    .HasCharSet("utf8")
                    .HasCollation("utf8_bin");

                entity.Property(e => e.Apwd)
                    .IsRequired()
                    .HasColumnName("APWD")
                    .HasColumnType("char(18)")
                    .HasCharSet("utf8")
                    .HasCollation("utf8_bin");
            });

            modelBuilder.Entity<Order>(entity =>
            {
                entity.HasKey(e => e.Oid)
                    .HasName("PRIMARY");

                entity.ToTable("order");

                //entity.HasIndex(e => e.Oid)
                //    .HasName("OID_UNIQUE")
                //    .IsUnique();

                //entity.HasIndex(e => e.Tid)
                //    .HasName("TID_index");

                //entity.HasIndex(e => e.Uid)
                //    .HasName("UID_index");

                entity.Property(e => e.Oid)
                    .HasColumnName("OID")
                    .HasColumnType("char(20)")
                    .HasCharSet("utf8")
                    .HasCollation("utf8_bin");

                entity.Property(e => e.Tid)
                    .HasColumnName("TID")
                    .HasColumnType("char(10)")
                    .HasCharSet("utf8")
                    .HasCollation("utf8_bin");

                entity.Property(e => e.Uid)
                    .HasColumnName("UID")
                    .HasColumnType("char(20)")
                    .HasCharSet("utf8")
                    .HasCollation("utf8_bin");

                //entity.HasOne(d => d.T)
                //    .WithMany(p => p.Order)
                //    .HasForeignKey(d => d.Tid)
                //    .HasConstraintName("TID_index");

                //entity.HasOne(d => d.U)
                //    .WithMany(p => p.Order)
                //    .HasForeignKey(d => d.Uid)
                //    .HasConstraintName("UID_index");
            });

            modelBuilder.Entity<Trip>(entity =>
            {
                entity.HasKey(e => e.Tid)
                    .HasName("PRIMARY");

                entity.ToTable("trip");

                //entity.HasIndex(e => e.Tid)
                //    .HasName("TID_index")
                //    .IsUnique();

                //entity.HasIndex(e => e.Vid)
                //    .HasName("VID");

                entity.Property(e => e.Tid)
                    .HasColumnName("TID")
                    .HasColumnType("char(10)")
                    .HasCharSet("utf8")
                    .HasCollation("utf8_bin");

                entity.Property(e => e.Begin)
                    .IsRequired()
                    .HasColumnName("BEGIN")
                    .HasColumnType("char(20)")
                    .HasCharSet("utf8")
                    .HasCollation("utf8_bin");

                entity.Property(e => e.End)
                    .IsRequired()
                    .HasColumnName("END")
                    .HasColumnType("char(20)")
                    .HasCharSet("utf8")
                    .HasCollation("utf8_bin");

                entity.Property(e => e.Time)
                    .HasColumnName("TIME")
                    .HasColumnType("time");

                entity.Property(e => e.Tnum).HasColumnName("TNUM");

                entity.Property(e => e.Tprice).HasColumnName("TPRICE");

                entity.Property(e => e.Vid)
                    .IsRequired()
                    .HasColumnName("VID")
                    .HasColumnType("char(10)")
                    .HasCharSet("utf8")
                    .HasCollation("utf8_bin");

                //entity.HasOne(d => d.V)
                //    .WithMany(p => p.Trip)
                //    .HasForeignKey(d => d.Vid)
                //    .OnDelete(DeleteBehavior.ClientSetNull)
                //    .HasConstraintName("VID");
            });

            modelBuilder.Entity<User>(entity =>
            {
                entity.HasKey(e => e.Uid)
                    .HasName("PRIMARY");

                entity.ToTable("user");

                //entity.HasIndex(e => e.Uid)
                //    .HasName("UID_index")
                //    .IsUnique();

                entity.Property(e => e.Uid)
                    .HasColumnName("UID")
                    .HasColumnType("char(20)")
                    .HasCharSet("utf8")
                    .HasCollation("utf8_bin");

                entity.Property(e => e.Age).HasColumnName("AGE");

                entity.Property(e => e.Id)
                    .IsRequired()
                    .HasColumnName("ID")
                    .HasColumnType("char(18)")
                    .HasCharSet("utf8")
                    .HasCollation("utf8_bin");

                entity.Property(e => e.Name)
                    .HasColumnName("NAME")
                    .HasColumnType("varchar(30)")
                    .HasCharSet("utf8")
                    .HasCollation("utf8_bin");

                entity.Property(e => e.Sex)
                    .IsRequired()
                    .HasColumnName("SEX")
                    .HasColumnType("char(1)")
                    .HasCharSet("utf8")
                    .HasCollation("utf8_bin");

                entity.Property(e => e.Tel).HasColumnName("TEL");

                entity.Property(e => e.Upwd)
                    .IsRequired()
                    .HasColumnName("UPWD")
                    .HasColumnType("char(18)")
                    .HasCharSet("utf8")
                    .HasCollation("utf8_bin");
            });

            modelBuilder.Entity<Vehicle>(entity =>
            {
                entity.HasKey(e => e.Vid)
                    .HasName("PRIMARY");

                entity.ToTable("vehicle");

                //entity.HasIndex(e => e.Vid)
                //    .HasName("VID_index")
                //    .IsUnique();

                entity.Property(e => e.Vid)
                    .HasColumnName("VID")
                    .HasColumnType("char(10)")
                    .HasCharSet("utf8")
                    .HasCollation("utf8_bin");

                entity.Property(e => e.Voh)
                    .IsRequired()
                    .HasColumnName("VOH")
                    .HasColumnType("char(1)")
                    .HasCharSet("utf8")
                    .HasCollation("utf8_bin");
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
